package cn.com.gridinfo.sooc.core.expand.score.activity;

import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.RadioButton;

import com.jeremy.arad.Arad;

import net.youmi.android.offers.OffersManager;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;
import cn.com.gridinfo.ads.AppConnect;
import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.base.BaseSoocActivity;
import cn.com.gridinfo.sooc.common.LocalMark;
import cn.dow.android.DOW;

/**
 * 赚取积分界面
 *
 * @author yingchunli
 */
public class GetScoreActivity extends BaseSoocActivity {

    @InjectView(R.id.question)
    RadioButton questionRb;//常见问题

    @InjectView(R.id.xize)
    RadioButton xizeRb;//积分细则

    @InjectView(R.id.ad_web)
    WebView adWeb;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.expand_score_getscore);
        ButterKnife.inject(this);
        initWebView();
    }

    //初始化数据
    private void initWebView() {
        adWeb.getSettings().setJavaScriptEnabled(true);
        adWeb.getSettings().setSupportMultipleWindows(true);
        adWeb.getSettings().setBuiltInZoomControls(true); // 显示放大缩小
        adWeb.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);// 默认缩放模式
        adWeb.getSettings().setUseWideViewPort(true);// 无限缩放
        questionRb.setChecked(true);
    }

    /**
     * 常见问题的选中
     */
    @OnCheckedChanged(R.id.question)
    void onLeftClick() {
        if (questionRb.isChecked()) {
            // 显示常见问题
            adWeb.loadUrl("file:///android_asset/index.html");
            adWeb.loadUrl(Arad.preferences.getString(LocalMark.SERVER_URL.getName(), "") + "/index.php/home/Public/question.html");
        }
    }

    /**
     * 积分细则的选中
     */
    @OnCheckedChanged(R.id.xize)
    void onRightClick() {
        if (xizeRb.isChecked()) {
            // 显示积分细则
            adWeb.loadUrl("file:///android_asset/index.html");
            adWeb.loadUrl(Arad.preferences.getString(LocalMark.SERVER_URL.getName(), "") + "/index.php/home/Public/rules.html");
        }
    }

    /**
     * 第一个
     * 进入按钮的点击
     */
    @OnClick(R.id.ad1)
    void onBtn1Click() {
        //万普
        AppConnect.getInstance(this).showOffers(this,
                Arad.preferences.getString(LocalMark.SERVER_URL.getName(), "") + "_" + Arad.preferences.getString(LocalMark.USER_UID.getName(), ""));
    }

    /**
     * 第二个
     * 进入按钮的点击
     */
    @OnClick(R.id.ad2)
    void onBtn2Click() {
        //多盟
        DOW.getInstance(this).init(Arad.preferences.getString(LocalMark.SERVER_URL.getName(), "") + "_" + Arad.preferences.getString(LocalMark.USER_UID.getName(), ""));
        DOW.getInstance(this).show(this);
    }

    /**
     * 第三个
     * 进入按钮的点击
     */
    @OnClick(R.id.ad3)
    void onBtn3Click() {
        //有米
        OffersManager.getInstance(this).setUsingServerCallBack(true);
        OffersManager.getInstance(this).setCustomUserId(Arad.preferences.getString(LocalMark.SERVER_URL.getName(), "") + "_" + Arad.preferences.getString(LocalMark.USER_UID.getName(), ""));
        OffersManager.getInstance(this).onAppLaunch();
        OffersManager.getInstance(this).showOffersWall();
    }

    @Override
    public String setupToolBarTitle() {
        return "赚取积分";
    }

    @Override
    public boolean setupToolBarLeftButton(ImageView leftButton) {
        return true;
    }

    @OnClick(R.id.toolbar_leftbtn)
    void onToolbarLeftClick() {
        finish();
    }

}
